import { Button } from 'antd-mobile';
import axios from 'axios';

export default function Xhr() {
	const apiGet = () => {
		axios.get('http://127.0.0.1:9001/user?userId=12345');
		axios.get('http://127.0.0.1:9001/user', {
			params: {
				userId: '0001212',
			},
		});
	};

	const apiPost = () => {
		axios.post('http://127.0.0.1:9001/user', {
			firstName: 'Fred',
			lastName: 'Flintstone',
		});
	};

	const upload = e => {
		const formData = new FormData();
		formData.append('file', e.target.files[0]);
		axios.post('http://127.0.0.1:9001/upload', formData);
	};

	return (
		<div>
			<Button type='primary' onClick={apiGet}>
				get
			</Button>
			<Button type='primary' onClick={apiPost}>
				post
			</Button>
			<input type='file' onChange={upload} />
		</div>
	);
}
